import { DataTypes, Model } from 'sequelize'
import sequelize from './db'

export interface ITeachCase {
    id: number
    title: string
    content: string
}

class TeachCase extends Model {
    declare id: number
    declare title: string
    declare content: string
}

TeachCase.init(
    {
        id: {
            type: DataTypes.INTEGER,
            primaryKey: true,
            autoIncrement: true,
        },
        poster: {
            type: DataTypes.STRING,
            comment: '教学案例封面',
        },
        title: {
            type: DataTypes.STRING,
            allowNull: false,
            defaultValue: '新案例',
            comment: '教学案例标题',
        },
        key: {
            type: DataTypes.STRING,
            allowNull: false,
            comment: '标识，前端本地文件夹的名称',
        },
        description: {
            type: DataTypes.STRING,
            comment: '简介',
        },
        userId: {
            type: DataTypes.INTEGER,
            comment: '作者id'
        },
        publishTime: {
            type: DataTypes.DATE,
            comment: '发布时间'
        },
        comment: {
            type: DataTypes.TINYINT,
            comment: '是否开启评论'
        },
        doc: {
            type: DataTypes.TEXT('long'),
            comment: '文档',
        },
        viewCount: {
            type: DataTypes.INTEGER,
            defaultValue: 0,
            comment: '浏览量'
        },
        knowledgeBaseId: {
            type: DataTypes.INTEGER,
            comment: '知识库id'
        }
    },
    {
        // 这是其他模型参数
        sequelize, // 我们需要传递连接实例
        modelName: 'teachcase', // 我们需要选择模型名称
        paranoid: true,
    }
)

export default TeachCase
